import { WebGLComponent } from '../../core/webgl';
import { Color, ArrayHelper } from '../../core/util';

export class S05 extends WebGLComponent{
    static desc = 'shader语法概览';
    protected vs: string = `
        attribute vec3 a_Position;
        // precision lowp float; // 指定精度
        varying vec4 outColor; // vs -> fs 传递数据用
        void main() {
            gl_Position = vec4(a_Position,1.0);
        }
    `;
    protected fs: string = `
        // uniform vec4 color; // 全局变量
        void main() {
            //设置颜色
            gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
        }
    `;
    public renderWebGl() {
        let program = this.createProgram(this.vs, this.fs);
        this.gl.useProgram(program);
        let uniformColor = this.gl.getUniformLocation(program, 'color');
        this.gl.uniform4f(uniformColor, 0,1,1,1);
        let aPositionLocation = this.gl.getAttribLocation(program, 'a_Position');
        this.gl.bindAttribLocation(program, aPositionLocation, 'a_Position');
    }
}
